package com.yanfan.access.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.access.domain.NjPersonInfo;
import com.yanfan.access.service.INjPersonInfoService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 人员管理Controller
 *
 * @author genluo
 * @date 2024-11-05
 */
@Api(tags = "人员管理")
@RestController
@RequestMapping("/access/personInfo")
public class NjPersonInfoController extends BaseController {
    @Autowired
    private INjPersonInfoService njPersonInfoService;

    /**
     * 查询人员管理列表
     */
    @ApiOperation("人员管理分页列表")
    @PreAuthorize("@ss.hasPermi('access:personInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjPersonInfo njPersonInfo) {
        startPage();
        List<NjPersonInfo> list = njPersonInfoService.queryPageList(njPersonInfo);
        return getDataTable(list);
    }

    /**
     * 导出人员管理列表
     */
    @ApiOperation("导出人员管理列表")
    @PreAuthorize("@ss.hasPermi('access:personInfo:export')")
    @Log(title = "人员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjPersonInfo njPersonInfo) {
        List<NjPersonInfo> list = njPersonInfoService.queryPageList(njPersonInfo);
        ExcelUtil<NjPersonInfo> util = new ExcelUtil<NjPersonInfo>(NjPersonInfo.class);
        util.exportExcel(response, list, "人员管理数据");
    }

    /**
     * 获取人员管理详细信息
     */
    @ApiOperation("获取人员管理详细信息")
    @PreAuthorize("@ss.hasPermi('access:personInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(njPersonInfoService.getById(id));
    }

    /**
     * 新增人员管理
     */
    @ApiOperation("新增人员管理")
    @PreAuthorize("@ss.hasPermi('access:personInfo:add')")
    @Log(title = "人员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody NjPersonInfo njPersonInfo) {
        return toAjax(njPersonInfoService.save(njPersonInfo));
    }

    /**
     * 修改人员管理
     */
    @ApiOperation("修改人员管理")
    @PreAuthorize("@ss.hasPermi('access:personInfo:edit')")
    @Log(title = "人员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody NjPersonInfo njPersonInfo) {
        return toAjax(njPersonInfoService.updateById(njPersonInfo));
    }

    /**
     * 删除人员管理
     */
    @ApiOperation("删除人员管理")
    @PreAuthorize("@ss.hasPermi('access:personInfo:remove')")
    @Log(title = "人员管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(njPersonInfoService.removeBatchByIds(Arrays.asList(ids)));
    }
}
